﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using BAL;
namespace QuanLyTiemNET_DEV_LINQ
{
    public partial class XtraFrmThemChietKhau : DevExpress.XtraEditors.XtraForm
    {
        public XtraFrmThemChietKhau()
        {
            InitializeComponent();
        }

        private void XtraFrmThemChietKhau_Load(object sender, EventArgs e)
        {
            
            comboBox1.DataSource = BAL_LOAIKHACH.LayThpngTinLK();
            comboBox1.DisplayMember = "TenLoai";
            comboBox1.ValueMember = "MaLoaiKH";
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            
            txtCHIETKHAU.Text = "0";
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string err = null;
            try
            {
                if (BAL_BANGCHIETKHAU.ThemBCK(ref err, comboBox1.SelectedValue.ToString(), DateTime.Now.ToString(), float.Parse(txtCHIETKHAU.Text)))
                {

                    DataTable dt = BAL_BANGCHIETKHAU.LayBCK();
                    int countRow = dt.Rows.Count;

                    DataTableReader dtr = new DataTableReader(dt);
                    while (dtr.Read() && countRow != 1)
                    {
                        if (dtr["MaLoaiKH"].ToString().Equals(comboBox1.SelectedValue.ToString()))
                        {
                            BAL_BANGCHIETKHAU.DanhDauXoa(ref err, int.Parse(dtr["MaBCK"].ToString()), true);
                            
                        }
                        countRow--;
                    }

                    MessageBox.Show("Thêm thành công!!!");
                }
                else
                    MessageBox.Show("Lỗi: " + err);

            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }
    }
}